<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>webrx</title>
    <style>
      .gotop { width: 50px; height: 50px; border-radius: 5px; background-color: #f00; position: fixed; right: 10px; bottom: 10px; display: none; transition: all 0.3s; cursor: pointer; }
      .gobottom { width: 50px; height: 50px; border-radius: 5px; background-color: rgb(69, 29, 179); position: fixed; top: 10px; right: 10px; transition: all 0.3s; cursor: pointer; }
    </style>
  </head>
  <body>
    <div class="gobottom" onclick="gobottom()"></div>
    <h3>hello01</h3> <h3>hello02</h3> <h3>hello03</h3> <h3>hello04</h3> <h3>hello05</h3> <h3>hello06</h3> <h3>hello07</h3> <h3>hello08</h3> <h3>hello09</h3> <h3>hello10</h3> <h3>hello11</h3> <h3>hello12</h3> <h3>hello13</h3> <h3>hello14</h3> <h3>hello15</h3> <h3>hello16</h3> <h3>hello17</h3> <h3>hello18</h3> <h3>hello19</h3> <h3>hello20</h3> <h3>hello21</h3> <h3>hello22</h3> <h3>hello23</h3> <h3>hello24</h3> <h3>hello25</h3> <h3>hello26</h3> <h3>hello27</h3> <h3>hello28</h3> <h3>hello29</h3> <h3>hello30</h3> <h3>hello31</h3> <h3>hello32</h3> <h3>hello33</h3> <h3>hello34</h3> <h3>hello35</h3> <h3>hello36</h3> <h3>hello37</h3> <h3>hello38</h3> <h3>hello39</h3> <h3>hello40</h3> <h3>hello41</h3> <h3>hello42</h3> <h3>hello43</h3> <h3>hello44</h3> <h3>hello45</h3> <h3>hello46</h3> <h3>hello47</h3> <h3>hello48</h3> <h3>hello49</h3> <h3>hello50</h3>
    <div class="gotop"></div>
    <script>
      let aaa;
      function gobottom() {
        aaa = setInterval(() => {
          document.documentElement.scrollTop +=
            document.documentElement.scrollHeight / 10;
          //if(document.documentElement.scrollTop == 0) clearInterval(an);
          //document.title = document.documentElement.scrollTop;

          if (
            document.documentElement.scrollHeight - getClientHeight() ==
            document.documentElement.scrollTop
          )
            clearInterval(aaa);
        }, 30);
      }

      function getClientHeight() {
        var clientHeight = 0;
        if (
          document.body.clientHeight &&
          document.documentElement.clientHeight
        ) {
          var clientHeight =
            document.body.clientHeight < document.documentElement.clientHeight
              ? document.body.clientHeight
              : document.documentElement.clientHeight;
        } else {
          var clientHeight =
            document.body.clientHeight > document.documentElement.clientHeight
              ? document.body.clientHeight
              : document.documentElement.clientHeight;
        }
        return clientHeight;
      }

      window.onscroll = function () {
          console.log(document.documentElement.clientHeight);
        //console.log(document.documentElement.scrollHeight - getClientHeight());
        let t = document.documentElement.scrollTop;
        let gt = document.querySelector(".gotop");
        document.title = t;
        if (t >= 800) {
          gt.style.display = "block";
        } else {
          gt.style.display = "none";
        }

        let an;
        gt.onclick = function () {
          an = setInterval(() => {
            document.documentElement.scrollTop -=
              document.documentElement.scrollTop / 2;
            if (document.documentElement.scrollTop == 0) clearInterval(an);
          }, 30);
        };
      };
    </script>
  </body>
</html>
